/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-11-30     yoyoyes      first version
 */

#include "timer_static_demo.h"

static struct rt_timer timer1;
static struct rt_timer timer2;

static int cnt = 0;

/*
 * @brief  定时器1超时函数
 *
 * @param  parameter 定时器超时函数参数
 *
 * @return None
 */
static void timeout1(void *parameter)
{
    rt_kprintf("periodic timer is timeout\n");

    if(cnt++ >= 9)
    {
        rt_timer_stop(&timer1);
    }
}

/*
 * @brief  定时器2超时函数
 *
 * @param  parameter 定时器超时函数参数
 *
 * @return None
 */
static void timeout2(void *parameter)
{
    rt_kprintf("one shot timer is timeout\n");
}

/*
 * @brief  定时器Demo函数
 *
 * @param  None
 *
 * @return None
 */
void timer_static_demo(void)
{
    /* 初始化定时器1 */
    rt_timer_init(&timer1, "timer1", timeout1, RT_NULL, 10, RT_TIMER_FLAG_PERIODIC);

    /* 初始化定时器2 */
    rt_timer_init(&timer2, "timer2", timeout2, RT_NULL, 30, RT_TIMER_FLAG_ONE_SHOT);

    /* 启动定时器 */
    rt_timer_start(&timer1);
    rt_timer_start(&timer2);
}
